package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EPRangeDao;
import com.hongxun.modules.eys.entity.EPRangeEntity;
import com.hongxun.modules.eys.service.EPRangeService;



@Service("ePRangeService")
public class EPRangeServiceImpl implements EPRangeService {
	@Autowired
	private EPRangeDao ePRangeDao;
	
	@Override
	public EPRangeEntity queryObject(String guid){
		return ePRangeDao.queryObject(guid);
	}
	
	@Override
	public List<EPRangeEntity> queryList(Map<String, Object> map){
		return ePRangeDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return ePRangeDao.queryTotal(map);
	}
	
	@Override
	public void save(EPRangeEntity ePRange){
        if(ePRange.getGuid()==null||ePRange.getGuid().equals("")) {

		    ePRange.setGuid(UUID.randomUUID().toString());
        }
		ePRangeDao.save(ePRange);
	}
	
	@Override
	public void update(EPRangeEntity ePRange){
		ePRangeDao.update(ePRange);
	}
	
	@Override
	public void delete(String guid){
		ePRangeDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		ePRangeDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<EPRangeEntity> entities) {
		for (EPRangeEntity d : entities) {
			if (d.getPRDatastate().equals("删除")) {
				ePRangeDao.delete(d.getGuid());
			} else {
				EPRangeEntity epRangeEntity = ePRangeDao.queryObject(d.getGuid());
				if (epRangeEntity == null) {
					ePRangeDao.save(d);
				} else {
					ePRangeDao.update(d);
				}
			}
		}
	}
}
